package com.gxa.community.admin.controller.user;

/**
 * 作者： Juran on 2022-07-20 8:21
 * 作者博客：iit.la
 */

import com.gxa.community.admin.service.bill.BillService;
import com.gxa.community.core.pojo.dto.bill.BillDto;
import com.gxa.community.core.pojo.dto.bill.storage.BillStorageDto;
import com.gxa.community.core.utils.R;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/bill")
public class BillController {
    //TODO 数据校验

    private final BillService billService;

    public BillController(BillService billService) {
        this.billService = billService;
    }
    @PostMapping("addBillInfo")
    public R addBillInfo(@RequestBody BillStorageDto billStorageDto){
        return billService.addBillInfo(billStorageDto);
    }


    //DO编辑对账信息内容
    @PutMapping("editBill")
    public R editBill(BillDto billDto) {
        if (ObjectUtils.isEmpty(billDto.getNo()) &&
        ObjectUtils.isEmpty(billDto.getStatus()))
            return R.error("请检查设置参数");

        return billService.editBill(billDto);
    }

    @PostMapping("queryBill")
    public R queryBill(@RequestBody BillDto billDto,
                       long page,
                       long size) {
        return billService.queryBill(billDto,
                ObjectUtils.isEmpty(page) ? 1 : page,
                ObjectUtils.isEmpty(page) ? 5 : size);
    }
}
